#!/usr/bin/env bash

help(){
    cat<<__EOF__
    usage: m firewall [ status | enable | disable | list | add | remove | help ]

    Examples:
       m firewall status                # Show status
       m firewall enable                # Enable firewall
       m firewall disable               # Disable firewall
       m firewall list                  # List applications handled by firewall
       m firewall add /path/to/file     # Add app to firewall
       m firewall remove /path/to/file  # Remove app from firewall

__EOF__
}



case $1 in
    help)
        help
        ;;
    status)
        sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
        ;;
    enable)
        sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on
        ;;
    disable)
        sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off
        ;;
    list)
        sudo /usr/libexec/ApplicationFirewall/socketfilterfw --list
        ;;
    add)
        [ -z "$2" ] && help && exit 1
        sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add $2
        ;;
    remove)
        [ -z "$2" ] && help && exit 1
        sudo /usr/libexec/ApplicationFirewall/socketfilterfw --remove $2
        ;;
    *)
        help
        ;;
esac

# vim: ts=4 sw=4 softtabstop=4 expandtab
